package net.maxwoods.nimble.script;

import lombok.extern.slf4j.Slf4j;

import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

@Slf4j
public class ScriptMain {

    public static void main(String[] args) throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        manager.getEngineFactories().forEach(
                factory ->
                {

                    String engineName = factory.getEngineName();
                    String engineVersion = factory.getEngineVersion();
                    String languageName = factory.getLanguageName();
                    String languageVersion = factory.getLanguageVersion();
                    ScriptEngine engine = factory.getScriptEngine();
                    System.out.println(String.format("引擎名称：%s\t引擎版本：%s\t语言名称：%s\t语言版本：%s\t\n",
                            engineName, engineVersion, languageName, languageVersion));
                }
        );


        ScriptEngine engine = manager.getEngineByName("ECMAScript");
        engine.getBindings(ScriptContext.ENGINE_SCOPE).

                put("ld", new LDConsole());
        log.info("{}", engine.eval("ld.cmd();"));
        log.info("===================================================");
    }
}